package ru.cod.rs.screens;

import java.util.List;

import ru.cod.rs.interfaces.Game;
import ru.cod.rs.interfaces.Graphics;
import ru.cod.rs.interfaces.Input.TouchEvent;
import ru.cod.rs.objects.Assets;
import ru.cod.rs.objects.Screen;
import ru.cod.rs.objects.gameobjects.GameWorld;
import android.graphics.Color;

public class GameScreen extends Screen {
	GameWorld world;
	Graphics gr;

	public GameScreen(Game g) {

		super(g);
		world = new GameWorld(game);
		gr = game.getGraphics();
	}

	@Override
	public void update(float delta) {
		List<TouchEvent> events = game.getInput().getTouchEvents();

		if (events.size() > 0) {
			for (TouchEvent event : events) {
				if (event.type == TouchEvent.TOUCH_UP) {
					if (event.x < 32 && event.y < 32) {
						world.addSimpleUnit();
					}
				}
			}
		}
		world.update();
	}

	@Override
	public void render(float delta) {
		gr.clear(Color.BLACK);
		world.render();
		drawUI();

	}

	private void drawUI() {
		gr.drawBitmap(Assets.unit, 0, 0);
	}
}
